package com.jackiechancinema.ssm.controller;

import com.jackiechancinema.ssm.bo.DepartmentBo;
import com.jackiechancinema.ssm.entity.Department;
import com.jackiechancinema.ssm.service.Inte.DepartmentService;
import com.jackiechancinema.ssm.vo.PageVo;
import com.jackiechancinema.ssm.vo.R;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api/department/")
public class DepartmentController {
    @Autowired
    private DepartmentService service;


    @GetMapping("selectpage")
    public PageVo<Department> page(DepartmentBo departmentBo){
        return service.page2(departmentBo);
    }
    /**
     * 新增
     * @param department
     * @return
     */
    @PostMapping("insert")
    public R insert(Department department){
        return service.insert(department);
    }
    /**
     * 批量新增
     * @param file
     * @return
     */
    @RequestMapping("insertBatch")
    public R insertBatch(MultipartFile file){
//        System.out.println(file.getName());
        return service.insertBatch(file);
    }
    /**
     * 删除
     * @param depart_id
     * @return
     */
    @PostMapping("delete")
    public R delete(int depart_id){
        return service.delete(depart_id);
    }

    /**
     * 修改
     * @param department
     * @return
     */
    @PostMapping("update")
    public R update(Department department){
        return service.update(department);
    }

    /**
     * 下载，导出excel表格
     * @param bo
     * @param response
     */
    @GetMapping("download")
    public void download(DepartmentBo bo, HttpServletResponse response){
        service.exportExcel(bo,response);
    }
}
